import { message } from "@/utils/message";
import { ref } from "vue";
import { delAppfun, getAppFunList } from "@/api/application";

import { ElMessage } from "element-plus";

const dataList = ref();
const modeID = ref();
const state = ref(false);
export function useColumns() {
  state.value = false;

  const handleDelete = async row => {
    //message(`您删除了第 ${index} 行，数据为：${JSON.stringify(row)}`);
    const Result = await delAppfun({ id: row.id });
    if (Result.isSuccess) {
      message("删除成功!");
      loadData();
      //console.log(row);
    } else {
      message(Result.msg);
    }
  };

  const columns: TableColumnList = [
    {
      label: "功能名称",
      prop: "funName",
      width: 150
    },
    {
      label: "功能图标",
      slot: "image"
    },
    {
      label: "开发者编号",
      prop: "addUser"
    },
    {
      label: "添加日期",
      slot: "dateSlot",
      sortable: true
    },
    {
      align: "center",
      // 自定义表头
      label: "操作",
      slot: "operation",
      width: 150
    }
  ];
  const loadData = async () => {
    const Result = await getAppFunList({ modelID: modeID.value, falg: 0 });
    if (Result.isSuccess) {
      dataList.value = Result.result;
    } else {
      ElMessage(Result.msg);
    }
  };
  return {
    columns,
    state,
    loadData,
    dataList,
    modeID,
    handleDelete
  };
}
